package com.fancyears.clientfunction.controller;

import com.fancyears.clientfunction.bean.ClientConfiguration;
import com.fancyears.clientfunction.dao.TestDao;
import com.fancyears.clientfunction.pojo.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: fancyears·milos·malvis
 * @Description:
 * @Date: Created in  2019/1/21 13:33
 * @Modified By:
 */
@RestController
@EnableConfigurationProperties({ClientConfiguration.class})
@RequestMapping("fancyears/test")
public class LocalTestController {
    @Autowired
    ClientConfiguration clientConfiguration;
    @Autowired
    TestDao testDao;
    @RequestMapping("clientConfiguration")
    public String getConfiguration(){
        return "test"+clientConfiguration.getLevel()+clientConfiguration.isDebug();
    }

    @RequestMapping("getTest")
    public String getTest(@RequestParam(value = "id") Long id) throws Exception {
        Test t=testDao.selectByPrimaryKey(id);
        if(t!=null){
            return  "id="+t.getId()+"\tname"+t.getName()+"\t"+t.getLocation();
        }
        return null;
    }
    private String m = "Testing:";
    @Value("${server.port}")
    String port;
    private int o = 0;

    @RequestMapping("/hi")
    public String home(@RequestParam(value = "name", defaultValue = "defaultValue") String name) {
        return "hi " + name + " ," + m + this.getClass().getCanonicalName();
    }

}
